/**
 * Copyright (C) 2008 Christopher Allen Ogden
 *
 *     This file is part of Odysi.
 *
 *  Odysi is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  Odysi is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Odysi.  If not, see <http://www.gnu.org/licenses/>.
 */

#pragma once
#include <SDL.h>
#include <SDL_mixer.h>
#include <SDL_opengl.h>
#include "log.h"

class GameObject
{
public:
    /**
     * Constructor.
     *
     * @param width     The width of the screen.
     * @param height    The height of the screen.
     * @param title     The title of the window.
     */
    explicit inline GameObject(int width, int height, const char *title)
    {
#ifdef WIN32
        SDL_putenv("SDL_VIDEODRIVER=directx");
#else
        //SDL_putenv("SDL_VIDEODRIVER=dga");
#endif
        SDL_Init(SDL_INIT_EVERYTHING);
        if(SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 1) == 1)
        {
            Log::GS().info("Swap control could not be enabled.");
        }
        SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
        SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
        SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
        SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32);
        SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
        const SDL_VideoInfo* info = SDL_GetVideoInfo();
        SDL_SetVideoMode(width, height, info->vfmt->BitsPerPixel, SDL_OPENGL);
        SDL_WM_SetCaption(title, title);
        // Initialize the audio device.
        Mix_OpenAudio(22050, AUDIO_S16SYS, 2, 4096);
        SDL_EnableUNICODE(1);
        SDL_ShowCursor(SDL_DISABLE);
        SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
    }

    /**
     * Destructor.
     */
    inline ~GameObject()
    {
        // Stop the music.
        Mix_HaltMusic();

        // Close the audio device.
        Mix_CloseAudio();

        SDL_Quit();
    }
private:
};

